//
//  BQBaseView.swift
//  BQWB
//
//  Created by laibingqiang on 16/10/25.
//  Copyright © 2016年 laibingqiang. All rights reserved.
//

import UIKit

class BQBaseView: UIView {

    //定义的闭包
    var colure:(()->())?
    override init(frame:CGRect){
        
        super.init(frame: frame)
        
        
        
        setupUI()
    }
    //按钮监听方法
    @objc private func loginClink(){
        
        colure?()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //设置子控件的方法
    func setupSubViews(text:String?,img:String?){
        
        if let t = text,let i = img {
            
            self.messageL.text = t
            
            self.iconImgView.image = UIImage(named: i)
            
            self.maskImgView.isHidden = true
            
            self.circleImgView.isHidden = true

        }
        else
        {
            
            animationed()
        }
        
    }
    //动画方法
    private func animationed(){
        
        let anim = CABasicAnimation(keyPath: "transform.rotation")
        
        anim.toValue = M_PI * 2
        
        anim.duration = 20
        
        anim.repeatCount = MAXFLOAT
        
        anim.isRemovedOnCompletion = false
        
        circleImgView.layer.add(anim, forKey: nil)
    }
    
    //设置界面的方法
    private func setupUI(){
        
        backgroundColor = UIColor(white: 237/255, alpha: 1)
        addSubview(circleImgView)
        
        addSubview(maskImgView)
        
        addSubview(iconImgView)
        
        addSubview(messageL)
        
        addSubview(registerBtn)
        
        addSubview(loginBtn)
        
        circleImgView.snp_makeConstraints { (make) in
            
            make.center.equalTo(self)
            
        }
        
        maskImgView.snp_makeConstraints { (make) in
            
            make.center.equalTo(self)
        }
        
        iconImgView.snp_makeConstraints { (make) in
            make.center.equalTo(self)
        }
        
        messageL.snp_makeConstraints { (make) in
            
            make.width.equalTo(230)
            
            make.centerX.equalTo(self)
            
            make.top.equalTo(maskImgView.snp_bottom).offset(16)
        }
        
        registerBtn.snp_makeConstraints { (make) in
            make.size.equalTo(CGSize(width: 100, height: 30))
            make.left.equalTo(messageL)
            make.top.equalTo(messageL.snp_bottom).offset(16)
        }
        
        loginBtn.snp_makeConstraints { (make) in
            make.size.equalTo(registerBtn)
            make.right.equalTo(messageL)
            make.top.equalTo(registerBtn)
        }
        
        
        
        
    }
    //懒加载子控件
    private lazy var circleImgView:UIImageView = UIImageView(imgName:"visitordiscover_feed_image_smallicon")
    
    fileprivate lazy var maskImgView:UIImageView = UIImageView(imgName: "visitordiscover_feed_mask_smallicon")
    
    fileprivate lazy var iconImgView:UIImageView = UIImageView(imgName: "visitordiscover_feed_image_house")
    
    fileprivate lazy var messageL:UILabel = {
        
        let lab = UILabel(text: "关注一些人，回这里看看有什么惊喜关注一些人，回这里看看有什么惊喜", textColor: UIColor.darkGray, fontSize: 14)
        lab.numberOfLines = 0
        lab.textAlignment = .center
        return lab
    }()
    fileprivate lazy var registerBtn:UIButton = {
        
        let btn = UIButton(target: self, action: #selector(loginClink), imgName: nil, backImg: "common_button_white", title: "注册")
        btn.setTitleColor(UIColor.orange, for: UIControlState.normal)
        
        return btn
        
    }()
    
    fileprivate lazy var loginBtn:UIButton = {
        let btn = UIButton(target: self, action: #selector(loginClink), imgName: nil, backImg: "common_button_white", title: "登陆")
        btn.setTitleColor(UIColor.orange, for: UIControlState.normal)
        
        return btn
        
    }()
}
